# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gc
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=8.0.6
pkgrel=1
pkgdesc="A garbage collector for C and C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.hboehm.info/gc"
license=("GPL")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libatomic_ops")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
options=('staticlibs' '!debug' 'strip')
source=("https://github.com/ivmai/bdwgc/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('3b4914abc9fa76593596773e4da671d7ed4d5390e3d46fbf2e5f155e121bea11')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  # autoreconf to get updated libtool files with clang support
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  CFLAGS+=" -fcommon" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-threads=posix \
    --disable-dependency-tracking \
    --enable-large-config \
    --enable-cplusplus \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
